import { _decorator, Component, Node, resources, Layout, Prefab, instantiate, NodeEventType, director } from 'cc';
import * as ccenv from 'cc/env'
import MagicItem from '../data/MagicItem';
import PokerItem from '../data/PokerItem';
import { listenerClick } from '../core/EventHelper';
import { ResLoader } from '../../libs/loader/ResLoader';
import { MagicHandle } from '../manager/MagicManager';
import { GameManager } from '../manager/GameManager';

const { ccclass, property } = _decorator;

const isDevelopment = ccenv.DEBUG;
const isProduction = !ccenv.DEBUG;
const isPC = ccenv.MAC || ccenv.WINDOWS || ccenv.LINUX;
const EventClick = isPC ? NodeEventType.MOUSE_DOWN : NodeEventType.TOUCH_START;

@ccclass('PokerStartDialog')
export class PokerStartDialog {

    @property(Node)
    root: Node = null!;

    @property(Node)
    game_new: Node = null!;

    @property(Node)
    game_continue: Node = null!

    @property(Node)
    mine_poker: Node = null!

    @property(Node)
    store_poker: Node = null!

    @property(Node)
    store_update: Node = null!


    show(game: GameManager, call: (isNew: boolean) => void) {
        this.root.active = true;
        // 更新魔法牌

        // 添加监听
        const unbind_new = listenerClick(this.game_new, (node) => {
            close();
            call(true);
        });

        const unbind_continue = listenerClick(this.game_continue, (node) => {
            close()
            call(false);
        });

        const close = () => {
            unbind_new();
            unbind_continue();
            this.root.active = false;
        }

        return close;
    }



    // async addPoker() {
    //     const resLoader = new ResLoader();
    //     const prefab = await resLoader.loadAsync('prefab/Poker', Prefab)
    //     const magicItem = new MagicItem(MagicHandle.Add_Money_10, instantiate(prefab))
    //     this.back.addChild(magicItem.node);
    //     listenerClick(magicItem.node, async () => {
    //         const prefab = await resLoader.loadAsync('bundle', 'prefab/PokerDialog', Prefab)
    //         const pokerDialog = instantiate(prefab);
    //         this.node.parent?.addChild(pokerDialog);
    //         const comp = pokerDialog.getComponent(PokerDialogComponent)
    //         if (comp) {
    //             comp.showPoker(magicItem, {
    //                 handle(poker) {
    //                     return true;
    //                 },
    //             })
    //         }
    //     });
    // }
}

